package com.zmn.oms.admin.controller.work.modify;

import com.zmn.oms.admin.controller.work.WorkBaseController;
import com.zmn.oms.common.dto.ResultDTO;
import com.zmn.oms.model.dto.work.modify.OrderPostListDTO;
import com.zmn.oms.model.vo.work.modify.OrderPostVO;
import com.zmn.oms.services.interfaces.express.OrderPostService;
import com.zmn.oms.zmn.business.interfaces.work.OrderWorkOrderPostBService;
import com.zmn.oms.zmn.business.interfaces.work.ZsOrderWorkOperatePermissionBService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @ClassName WorkExpressDeliveryController
 * @Description 物流快递信息操作
 * @Author xiaofei
 * @Date 2020/7/24
 * @Version 1.0
 */
@Controller
@RequestMapping("/work/modify")
public class WorkOrderPostController extends WorkBaseController {

    @Autowired
    private OrderPostService orderPostService;
    @Autowired
    private OrderWorkOrderPostBService orderWorkOrderPostBService;
    @Autowired
    private ZsOrderWorkOperatePermissionBService orderWorkOperatePermissionBService;

    /**
     * @descript: 快递信息
     * @param: [code]
     * @return: ModelAndView
     * @author: xiaofei
     * @date: 2020/7/24 16:37
     * @version: v1.0
     */
    @RequestMapping("/orderPost")
    public ModelAndView findOrderPost(Long orderId, Long workId) {
        ModelAndView mv = new ModelAndView("work/modify/orderpost");

        try {
            List<OrderPostVO> orderPostList = orderWorkOrderPostBService.listOrderPostByOrderId(orderId);
            mv.addObject("orderId", orderId);
            mv.addObject("workId", workId);
            mv.addObject("orderPostList", orderPostList);
            // 快递公司
            mv.addObject("expressCompanyList", super.listExpressCompany());

        } catch (Exception e) {
            e.printStackTrace();
        }
        return mv;
    }

    /**
     * @descript: 快递信息操作保存
     * @author: xiaofei
     * @param: [orderPostListDTO]
     * @return: com.zmn.common.dto2.ResponseDTO
     * @date: 2020/7/24 16:34
     * @version: v1.0
     */
    @RequestMapping("/save/orderPost")
    @ResponseBody
    public ResultDTO saveOrderPostList(@RequestBody OrderPostListDTO orderPostListDTO) {

        /*OperatePermissionVO operatePermission = orderWorkOperatePermissionBService.getOperatePermission(orderPostListDTO.getOrderId(), orderPostListDTO.getWorkId(), OrderConsts.ORDER_OP_TYPE_EXPRESS);
        if (!operatePermission.getCanOperate()) {
            return ResultDTO.fail(operatePermission.getMsg());
        }*/

        orderWorkOrderPostBService.saveOrderPostList(orderPostListDTO);

        return ResultDTO.success();
    }

}
